﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mock1G3.BaseEntities;
using Mock1G3.DataAccess;
using Mock1G3.BussinessLogic;

namespace Mock1G3.UserControl.WithDraw
{
    public partial class SelectAmount : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void WithDraw(decimal amount)
        {
            Card card = new Card();
            ATM atm = new ATM();
            card.AccountID = Int32.Parse(Session["AccountID"].ToString());
            card.CardNo = Session["CardNo"].ToString();
            atm.ATMID = Int32.Parse(Session["ATMID"].ToString());
            if(!WithDrawAccess.CheckValidAmountWithBalance(amount, card.AccountID))
            {
                WebMsgBox.Show("You don't have enought balance. Please select agian!");
            }
            else if(!WithDrawAccess.CheckOverDrawLimit(amount, card.AccountID))
            {
                WebMsgBox.Show("Your withdraw was limited. You can't withdraw today.");
            }
            else
            {
                 WithDrawLogic.WithDrawMoney(amount, card.AccountID, atm.ATMID, card.CardNo);
                 WebMsgBox.Show("Withdraw successful!");
                 foreach (Control item in this.Parent.Controls)
                 {
                     if (item.ID.Equals("ucPrintReceipt"))
                     {
                         item.Visible = true;
                         continue;
                     }
                     item.Visible = false;
                 }
            }
        }
        public void SelectValues_Click(object sender, EventArgs e)
        {
            switch ((sender as System.Web.UI.WebControls.Button).ID)
            {
                case "btn200000":                    
                    WithDraw(200000);
                    break;
                case "btn500000":
                    break;
                case "btn1000000":
                    WithDraw(1000000);
                    break;
                case "btn2000000":
                    WithDraw(2000000);
                    break;
                case "btn5000000":
                    WithDraw(5000000);
                    break;
                case "btnOther":
                    foreach (System.Web.UI.Control item in this.Parent.Controls)
                    {
                        if (item.ID.Equals("ucEnterAmount"))
                        {
                            item.Visible = true;
                            continue;
                        }
                        item.Visible = false;
                    }
                    break;
            }
        }
    }
}